/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       academy.cpp

	$Header: /game/academy.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#include "precompiled.h"
#pragma warning( disable: 4786 )
#include "academy.h"

#include "adv_object_type.h"
#include "adventure_frame.h"
#include "ai_value.h"
#include "army.h"
#include "basic_dialog.h"
#include "creature_array.h"
#include "game_replace_keywords.h"
#include "hero.h"
#include "object_registration.h"
#include "player.h"
#include "replace_keywords.h"
#include "simple_dialog.h"

static t_object_registration<t_academy> k_registration( k_adv_object_academy );

// -------------------------------------------------------------
// hero gains 1000 experience from visiting an academy (learning stone)
// -------------------------------------------------------------
t_academy::t_academy(  std::string const& source )
         : t_single_use_object( source )
{
}

bool t_academy::are_all_heroes_ineligible( t_army* army ) const
{
	t_creature_array& creatures = army->get_creatures();
	int                 i;
	t_hero*             hero;
	bool				any_heroes = false;
	t_player*           player = army->get_owner();
	bool				can_add_experience = false;

	for (i = 0; i < t_creature_array::k_size; i++)
	{
		hero = creatures[i].get_hero();
		if (hero == 0)
			continue;

		any_heroes = true;
	    
        if (!(hero->can_add_experience( player )))
            continue;
	
        can_add_experience = true;
    }

	if (any_heroes == false)
        return false;
    
    return (!can_add_experience);
}

// -------------------------------------------------------------
// hero gains 1000 experience from visiting an academy
// -------------------------------------------------------------
std::string t_academy::add_icons( t_basic_dialog* dialog, std::string const& text,
								  std::vector<t_hero*> const& heroes )
{
	dialog->add_experience( 1000 );
	return replace_keywords( text, "%experience", "1000" );
}

// -------------------------------------------------------------
// hero gains 1000 experience from visiting an academy
// -------------------------------------------------------------
void t_academy::visit( t_hero* hero )
{
	hero->add_experience( 1000 );
}

// -------------------------------------------------------------
// hero gains 1000 experience from visiting an academy
// -------------------------------------------------------------
float t_academy::ai_value( t_adventure_ai const& ai, t_creature_array const& army, int move_cost ) const
{
	const float bonus = 1000;
	float value = 0.0f;
	for (int i = 0; i < t_creature_array::k_size; i++)
	{
		t_creature_stack const& stack = army[i];
		t_hero const* hero = stack.get_const_hero();
		if (hero && !hero->has_visited(*this) && hero->can_add_experience( army.get_owner() )) 
			value += ai_value_of_xp( &army, bonus );
	}
	return value;
}


